package com.ruoyi.common.core.redis;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
/* loaded from: RedisLock.class */
public class RedisLock {
    @Autowired
    private RedissonClient redissonClient;

    public RLock getRLock(String lockKey) {
        return this.redissonClient.getLock(lockKey);
    }

    public RLock lock(String lockKey) {
        RLock lock = getRLock(lockKey);
        lock.lock();
        return lock;
    }

    public Boolean tryLock(String lockKey, long leaseTime) {
        return tryLock(lockKey, 0, leaseTime, TimeUnit.SECONDS);
    }

    public Boolean tryLock(String lockKey, long leaseTime, TimeUnit unit) {
        return tryLock(lockKey, 0, leaseTime, unit);
    }

    public Boolean tryLock(String lockKey, long waitTime, long leaseTime, TimeUnit unit) {
        try {
            return Boolean.valueOf(getRLock(lockKey).tryLock(waitTime, leaseTime, unit));
        } catch (InterruptedException e) {
            return false;
        }
    }

    public void unlock(String lockKey) {
        getRLock(lockKey).unlock();
    }

    public void unlock(RLock lock) {
        lock.unlock();
    }
}
